package xj.graph2d.template.uml;

import xj.graph2d.DrawShape;
import xj.graph2d.DrawShapeConstants;
import xj.graph2d.GraphEdgeBase;
import xj.graph2d.template.UMLClassDiagramTemplate;
import xj.graph2d.template.UMLTemplate;
import xj.model.uml.UMLAssociation;

public class UMLDelegationModelListener extends UMLAssociationModelListener {

  public UMLDelegationModelListener() {
  }

  public UMLDelegationModelListener(UMLTemplate template) {
    this(null, null, template);
  }

  public UMLDelegationModelListener(Object model, DrawShape shape,
				    UMLTemplate template) {
    super(model, shape, template);
  }

  @Override
  public void updateModel() {
    if (shape instanceof GraphEdgeBase && model instanceof UMLAssociation) {
      GraphEdgeBase edge = (GraphEdgeBase) shape;
      UMLAssociation dmodel = (UMLAssociation) model;
      String leftRole = edge.getLabel(DrawShapeConstants.ROLE_EDGE_TAIL_LABEL);
      dmodel.setLeftRole(leftRole);
    }
  }

  @Override
  public void updateShape() {
    if (shape instanceof GraphEdgeBase && model instanceof UMLAssociation) {
      GraphEdgeBase edge = (GraphEdgeBase) shape;
      UMLAssociation dmodel = (UMLAssociation) model;
      String leftRole = dmodel.getLeftRole();
      if (leftRole != null) {
	setLabel(edge, DrawShapeConstants.ROLE_EDGE_TAIL_LABEL, leftRole,
		 "delegate"); 
      }
    }
  }

}
